package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/public"
	"github.com/streadway/amqp"
	"strconv"
)

//执行极光推送任务
func main() {
	rpcJpush := new(public.Jpush).Init()

	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("public.log.jpushMsgQue"))

	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("public.queue.jpushMsgQue"), func(msg amqp.Delivery) {
		msgId, err  := strconv.Atoi( string(msg.Body) )
		if err != nil{
			utils.Logerr.Printf("极光推送任务，msgId 转换int失败，msgId:%s, err:%s", string(msg.Body), err)
			return
		}
		var reply bool
		err = rpcJpush.RunPushMsg(context.Background(), &msgId, &reply)
		if err != nil {
			utils.Logerr.Printf("极光推送任务，业务处理任务调用失败，msgId:%d, err:%s", msgId, err.Error())
		}

		utils.Logerr.Printf("极光推送任务，执行成功，msgId:%d", msgId)
	})

	if err != nil {
		utils.Logerr.Printf("极光推送任务错误，err: %s", err.Error())
	}

}

